<template>
  <div>
    <h1>权益添加</h1>
    <table class="table table-bordered">
      <tbody>
      <tr>
        <td>权益</td>
        <td><input type="text" v-model="info.ReighName"/></td>
      </tr>
      <tr>
        <td>权益状态</td>
        <td>
          <input type="radio" name="state" v-model="info.ReState" :value="1"/>启用
          <input type="radio" name="state" v-model="info.ReState":value="0"/>禁用
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
          <input type="button" value="提交" class="btn btn-success" @click="Ok"/>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import axios from "axios";
import moment from "moment";
import {useRoute,useRouter} from "vue-router";

const router = useRouter()
const route = useRoute()


//发送数据
let info:any=reactive({
  Id:route.query.id,
  "ReighName": "",
  "ReState": 1,
})
onMounted(() => {
  Find();
})
const Find=()=>{
  axios({
    url:"https://localhost:7032/api/User/FindRight",
    method:"get",
    params:{id:route.query.id}
  }).then((res)=>{
    console.log(res)
    Object.assign(info,res.data)
  })
}

const Ok=()=>{
  axios({
    url:"https://localhost:7032/api/User/UpdateReigh",
    method:"put",
    data:info
  }).then(res=>{
    console.log(res)
    if(res.data==-1)
    {
      alert("权益名称重复")
      return;
    }
    if(res.data>0)
    {
      alert("修改成功")

      return;
    }
    else
    {
      alert("修改失败")
    }
  })
}
</script>

<style scoped>

</style>